package com.ruoyi.pay.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.pay.entity.Commodity;
import com.ruoyi.pay.mapper.CommodityMapper;
import com.ruoyi.pay.service.CommodityService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class CommodityServiceImpl extends ServiceImpl<CommodityMapper, Commodity> implements CommodityService  {

    @Resource
    private CommodityMapper commodityMapper;
    @Override
    public void updateStatus(Long id, Integer status) {
        LambdaUpdateWrapper<Commodity> wrapper = new LambdaUpdateWrapper<>();
        wrapper.eq(Commodity::getId,id);
        wrapper.set(Commodity::getStatus,status);

        commodityMapper.update(null,wrapper);
    }

    @Override
    public List<Commodity> getListing() {
        LambdaQueryWrapper<Commodity> wrapper = new LambdaQueryWrapper<>();
        wrapper.like(Commodity::getStatus,1);
        return commodityMapper.selectList(wrapper);
    }

    @Override
    public List<Commodity> getList(String title) {

        LambdaQueryWrapper<Commodity> wrapper = new LambdaQueryWrapper<>();
        if (!("".equals(title))) {
            wrapper.like(Commodity::getTitle,title);
        }
        return commodityMapper.selectList(wrapper);
    }
}
